#pragma once
#ifndef __BOOK_H__
#define __BOOK_H__

#include <stdbool.h>

#define MAX_NAME_LEN 100

#define CHOOSE_MESSAGE  "Please Input:\n" \
                        "1.Add Book message\n" \
                        "2.Delete Book message\n" \
                        "3.Show Book message:\n"  \
                        "4.Change Book message\n" \
                        "5.Save for \'book.data\' file\n" \
                        "6.Load from \'book.data\'file\n" \
                        "7.Exit\n" \
                        "Your choice > "

#define INPUT_TARGET_BOOK "Input the book's name you want to modify: "

#define INPUT_NAME      "Input name: "
#define INPUT_PRICE     "Input price: "
#define INPUT_AMOUNT    "Input amount: "

#define FILE_NAME "book.data"

//Book信息节点
typedef struct _Book {
    char name[MAX_NAME_LEN];
    double price;
    int amount;
    struct _Book* prev;
    struct _Book* next;
} Book;

//链表节点头
typedef struct _BookSystem {
    int list_len;
    Book* book_list;
} BookSystem;


//(内部函数，不对外开放)
// 根据书名，返回book信息节点
Book* _find_book(BookSystem* booksys, char name[]);


//在链表尾部添加书籍信息
_Bool add_book(BookSystem* booksys, 
               char name[], 
               double price, 
               int amount);

//删除图书信息
_Bool del_book(BookSystem* booksys, char name[]);

//更改图书信息
_Bool change_book(BookSystem* booksys,
                  char old_name[],
                  char new_name[],
                  double new_price,
                  int new_amount);

//展示所有图书信息
void showall(BookSystem* booksys);

//序列化图书信息
_Bool serialize_booksys(BookSystem* booksys);

//反序列化图书信息
BookSystem* unserialize_booksys(char filename[]);


//释放所有申请的内存空间
void destory_booksys(BookSystem* booksys);


#endif